<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('第三方合作') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">

      <el-form-item :label="$t('机构类型')" prop="orgType">
        <el-select v-model="queryParams.orgType" :placeholder="$t('机构类型')" clearable>
          <el-option
            v-for="dict in orgTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('业务需求')" prop="businessNeeds">
        <el-input
          v-model="queryParams.businessNeeds"
          :placeholder="$t('业务需求')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('拟合作机构')" prop="cooperativeInstitutions">
        <el-input
          v-model="queryParams.cooperativeInstitutions"
          :placeholder="$t('拟合作机构')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:cooperation:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="fundCooperationList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('机构类型')" align="center" prop="orgType" :formatter="orgTypeFormat" />
      <el-table-column :label="$t('业务需求')" align="center" prop="businessNeeds" />
      <el-table-column :label="$t('拟合作机构')" align="center" prop="cooperativeInstitutions" />
      <el-table-column :label="$t('合作内容')" align="center" prop="cooperativeContents" />
      <el-table-column :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="fund:cooperation" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改第三方合作对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundCooperationForm ref="fundCooperationForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundCooperation, delFundCooperation } from '@/api/fund/cooperation/fundCooperation'
import fundCooperationForm from './fundCooperationForm.vue'
export default {
    components: {
        fundCooperationForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 第三方合作表格数据
          fundCooperationList: [],
          // 弹出层标题
          title: '第三方合作',
          // 是否显示弹出层
          formOpen: false,
          // 机构类型字典
          orgTypeOptions: [],
          // processKey: 当前节点配置的流程Key
          processKey: undefined,
          // 查询参数
          queryParams: {
              fundId: this.$route.query.id,
              fundName: undefined,
              orgType: undefined,
              involvedLitigation: undefined,
              businessNeeds: undefined,
              cooperativeInstitutions: undefined,
              cooperativeContents: undefined,
              institutionalAnalysis: undefined,
              costComparativeAnalysis: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('cooperation_org_type').then(response => {
          this.orgTypeOptions = response.data
      })
  },
  methods: {
    init(data) {
      this.processKey = data.processKey
    },
    /** 查询第三方合作列表 */
    getList() {
        this.loading = true
        listFundCooperation(this.queryParams).then(response => {
            this.fundCooperationList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 机构类型字典翻译
    orgTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.orgTypeOptions, row.orgType)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            fundId: undefined,
            fundName: undefined,
            orgType: undefined,
            involvedLitigation: undefined,
            businessNeeds: undefined,
            cooperativeInstitutions: undefined,
            cooperativeContents: undefined,
            institutionalAnalysis: undefined,
            costComparativeAnalysis: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.fundCooperationForm.init(null, this.processKey)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundCooperationForm.init(row, this.processKey)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return delFundCooperation(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(() => {
          this.loading = false
      })
    }
  }
}
</script>
